package com.karrysong.blog_springboot.vo;

import com.karrysong.blog_springboot.enums.ErrorCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * @ClassName: Result
 * @Author: KarrySong
 * @Date: 2022/8/2 15:24
 * @Description:
 */


@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result {

    private boolean success;

    private Integer code;

    private String msg;

    private Object data;


    public static Result success(Object data) {
        return new Result(true, 200, "success", data);
    }
    public static Result fail(Integer code, String msg) {
        return new Result(false, code, msg, null);
    }

    public static Result fail(ErrorCode errorCode){
        return new Result(false, errorCode.getCode(), errorCode.getMsg(), null);
    }

    public static Result fail(ErrorCode errorCode, String msg){
        return new Result(false, errorCode.getCode(), msg, null);
    }
}
